(function(jQuery) {
	/*
	 * 承运商配送区域查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierCYSPSQYUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var deliveryAreaName = encodeURI($('#condition').val());
			var gAccountNo = encodeURI($('#magnifierCYSPSQYPage_i_gAccountNo').val());
			var firstCode = encodeURI($('#magnifierCYSPSQYPage_i_firstCode').val());
			var secondCode = encodeURI($('#magnifierCYSPSQYPage_i_secondCode').val());
			var thirdCode = encodeURI($('#magnifierCYSPSQYPage_i_thirdCode').val());
			var fouthCode = encodeURI($('#magnifierCYSPSQYPage_i_fouthCode').val());
			// 创建列表DataGrid
			$('#magnifierCYSPSQYPage_cyspsqy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierCYSPSQYList.do?catch='
										+ new Date() 
										+ '&deliveryAreaName='
										+ deliveryAreaName
										+ '&gAccountNo='
										+ gAccountNo
										+ '&firstCode='
										+ firstCode
										+ '&secondCode='
										+ secondCode
										+ '&thirdCode='
										+ thirdCode
										+ '&fouthCode='
										+ fouthCode+'&Login_SessionId='+sessionId,
								method : 'get',
								title : $.i18n.prop("js.magnifier.title.cyspsqy"),
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 10,
								pageList : [10],
								columns : [ [ {
									field : 'deliveryAreaCode',
									title : $.i18n.prop("js.magnifier.datagrid.psqybm"),
									width : 150,
									align : 'left'
								}, {
									field : 'deliveryAreaName',
									title : $.i18n.prop("js.magnifier.datagrid.psqymc"),
									width : 180,
									align : 'left'
								}, {
									field : 'deliveryAreaType',
									title : $.i18n.prop("js.magnifier.datagrid.psqylx"),
									hidden : true,
									width : 0,
									align : 'left'
								}, {
									field : 'deliveryAreaTypeName',
									title : $.i18n.prop("js.magnifier.datagrid.psqylx"),
									width : 103,
									align : 'left'
								} ] ],

								onDblClickRow : function(rowIndex, rowData) {
									// 向父页面赋值
									if ($('#magnifierCYSPSQYPage_deliveryAreaId').val() != null && $('#magnifierCYSPSQYPage_deliveryAreaId').val().length > 0) {
										$("#" + $('#magnifierCYSPSQYPage_deliveryAreaId').val()).val(rowData.deliveryAreaId);
									}
									if ($('#magnifierCYSPSQYPage_deliveryAreaCode').val() != null && $('#magnifierCYSPSQYPage_deliveryAreaCode').val().length > 0) {
										$("#" + $('#magnifierCYSPSQYPage_deliveryAreaCode').val()).val(rowData.deliveryAreaCode);
									}
									if ($('#magnifierCYSPSQYPage_deliveryAreaType').val() != null && $('#magnifierCYSPSQYPage_deliveryAreaType').val().length > 0) {
										$("#" + $('#magnifierCYSPSQYPage_deliveryAreaType').val()).val(rowData.deliveryAreaType);
									}
									if ($('#magnifierCYSPSQYPage_deliveryAreaName').val() != null && $('#magnifierCYSPSQYPage_deliveryAreaName').val().length > 0) {
										$("#" + $('#magnifierCYSPSQYPage_deliveryAreaName').val(),
												window.parent.document).searchbox(
												'setValue', rowData.deliveryAreaName);
									}
									//关闭放大镜窗口
									$("#magnifier_window").window('close');
								},
								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
		},

		/**
		 * 查询
		 */
		search : function() {
			var deliveryAreaName = encodeURI($('#condition').val());
			var gAccountNo = encodeURI($('#magnifierCYSPSQYPage_i_gAccountNo').val());
			var firstCode = encodeURI($('#magnifierCYSPSQYPage_i_firstCode').val());
			var secondCode = encodeURI($('#magnifierCYSPSQYPage_i_secondCode').val());
			var thirdCode = encodeURI($('#magnifierCYSPSQYPage_i_thirdCode').val());
			var fouthCode = encodeURI($('#magnifierCYSPSQYPage_i_fouthCode').val());
			$('#magnifierCYSPSQYPage_cyspsqy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierCYSPSQYList.do?catch='
										+ new Date() 
										+ '&deliveryAreaName='
										+ deliveryAreaName
										+ '&gAccountNo='
										+ gAccountNo
										+ '&firstCode='
										+ firstCode
										+ '&secondCode='
										+ secondCode
										+ '&thirdCode='
										+ thirdCode
										+ '&fouthCode='
										+ fouthCode+'&Login_SessionId='+sessionId
							});
		}
	};
})(jQuery);
$.MagnifierCYSPSQYUtils.init();
